import fn  from '@/utils/checkEmpty.js'
// 根据获取已选数据的ids
function createIds (detailedTableData, unique) {
    let ids = []
    if (!fn.checkEmpty(detailedTableData)) {
        detailedTableData[0].children.forEach(item => {
            if (item.changeType !== -1 ) {
                ids.push(item[unique])
            }
        })
    }
    return ids
}
// 根据id去重
function distinctById (detailedTableData, unique) {
    let itemObj = {}
    if(fn.checkEmpty(detailedTableData)) {
        detailedTableData[0].children = detailedTableData[0].children.reduce((item, next)=>{
            if(next.changeType == -1 || next.oldState == -1) {
                item.push(next)
            }else{
                if(!itemObj[next[unique]]) {
                    item.push(next)
                    itemObj[next[unique]] = true
                }
            }
            return item
        }, [])
    }
}
export {
    createIds,
    distinctById
}